package com.greenhouse9.prog02.Backup;

import java.util.HashMap;

public class backup_result {

    private int  backup_no;
    private String backup_name;
    private int  detail_num;
    private long total_bytes;

    private HashMap<Integer, BackupResultDetail> m_detail = new HashMap<Integer, BackupResultDetail> ();

	private int backup_no_digit    = 15;
	private int backup_name_digit  = 30;
	private int detail_num_digit   = 20;
	private int total_bytes_digit  = 20;

    public backup_result(){
        m_detail.clear();
    }

    public void setBackupNo(int x){
        backup_no = x;
    }

    public int  getBackupNo(){
        return backup_no;
    }

    public void setBackName(String x){
        backup_name = x;
    }

    public String  getBackupName(){
        return backup_name;
    }

    public void setDetailNum(int x){
        detail_num = x;
    }

    public int  getDetailNum(){
        return detail_num;
    }

    public void setTotalBytes(long x){
        total_bytes = x;
    }

    public long  getTotalBytes(){
        return total_bytes;
    }

    public void setDetail(Integer i, BackupResultDetail x){
        m_detail.put(i,x);
    }

    public BackupResultDetail getDetail(Integer i){
        return m_detail.get(i);
    }

    public HashMap<Integer, BackupResultDetail> getDetail(){
        return m_detail;
    }

	public String Lpad (String s, short x, char ch){

		int length = s.length();

		if ( length >= x ) {
			return s.substring(length - x, x);
		}
		else {

			char [] ch_temp = new char [ x - length];
			for (int i=0; i < x - length; i++){
				ch_temp [i] = ch;
			}
			String str = new String(ch_temp);
			return str.concat(s);
		}
	}

	public void getFixedData(){

		String s_backup_no   = String.valueOf(backup_no);
		String s_backup_name = String.valueOf(backup_name);
		String s_detail_num  = String.valueOf(detail_num);
		String s_total_bytes = String.valueOf(total_bytes);

		System.out.print('1');
		System.out.print(Lpad(s_backup_no, (short)backup_no_digit, '0'));
		System.out.print(Lpad(s_backup_name, (short)backup_name_digit, ' '));
		System.out.print(Lpad(s_detail_num, (short)detail_num_digit, '0'));
		System.out.print(Lpad(s_total_bytes, (short)total_bytes_digit, '0'));
		System.out.println();
	}

}
